<template>
  <div class="clearfix selector">
    
    <div class="type-wrap">
      <div class="fl key">尺码</div>
      <div class="fl value">
        <ul class="type-list">
          <li v-for="(size,index) in sizeList" :key="size.sizeid" >
            <a @click="shoesBySize(size.sizeid)" :class="{active: size.sizeid == sid}">{{size.sizenum}}</a>
          </li>
        </ul>
      </div>
      <div class="fl ext"></div>
    </div>
    <div class="type-wrap">
      <div class="fl key">版型</div>
      <div class="fl value">
        <ul class="type-list">
          <li v-for="(type,index) in typeList" :key="type.tid">
            <a @click="shoesByType(type.tid)" :class="{active: type.tid == tid}">{{type.tname}}</a>
          </li>
        </ul>
      </div>
      <div class="fl ext"></div>
    </div>
    
    <div class="type-wrap">
      <div class="fl key">颜色</div>
      <div class="fl value">
        <ul class="type-list">
          <li v-for="(color,index) in colorList" :key="color.cid">
            <a @click="shoesByColor(color.cid)" :class="{active: color.cid == cid}">{{color.cname}}</a>
          </li>
         
        </ul>
      </div>
      <div class="fl ext">
      </div>
    </div>
    <div class="type-wrap">
      <div class="fl key">品牌</div>
      <div class="fl value">
        <ul class="type-list">
          <li v-for="(bland,index) in brandList" :key="bland.bid" >
            <a @click="shoesByBrandHandler(bland.bid)" :class="{active: bland.bid == bid}">{{bland.bname}}</a>
          </li>
        </ul>
      </div>
      <div class="fl ext">
      </div>
    </div>
  </div>
</template>

<script>
  import {mapState} from 'vuex';
  export default {
    name: 'SearchSelector',
    data() {
      return {
        bid: '',
        sid: '',
        tid: '',
        cid: ''
      }
    },
    mounted() {
      this.getData();
      this.getSize();
      this.getColor();
      this.getType();
    },
    methods: {
      getData() {
        this.$store.dispatch('getBrandList');
      },
      getSize() {
        this.$store.dispatch('getSizeList');
      },
      getColor() {
        this.$store.dispatch('getColorList');
      },
      getType() {
        this.$store.dispatch('getTypeList');
      },
      shoesByBrandHandler(bid) {
        this.bid = bid;
        this.$emit('shoesInfoByBrand', bid);
      },
      shoesByColor(cid) {
        this.cid = cid;
        this.$emit('shoesInfoByColor', cid);
        
      },
      shoesByType(tid) {
        this.tid = tid;
        this.$emit('shoesInfoByType', tid);
      },
      shoesBySize(sizeid) {
        this.sid = sizeid;
        this.$emit('shoesInfoBySize', sizeid);
      }
      
    },
    computed: {
      ...mapState({
        brandList: (state) => state.search.brandList,
        sizeList: (state) => state.search.sizeList,
        colorList: (state) => state.search.colorList,
        typeList: (state) => state.search.typeList
      })
    }
  }
</script>

<style lang="less" scoped>
  .selector {
    border: 1px solid #ddd;
    margin-bottom: 5px;
    overflow: hidden;
    background-color: #fff;
    .type-wrap {
      margin: 0;
      position: relative;
      border-bottom: 1px solid #ddd;
      overflow: hidden;
      padding: 0 15px;
      height: 40px;

      .key {
        
        line-height: 40px;
        text-align: right;
        font-weight: 700;
        height: 100%;
        float: left;
        color: c8c9c8;
        width: 50px;
        text-align: center;
      }

      .value {
        overflow: hidden;
        color: #333;
        padding:0 20px;
        // margin-left: 80px;
        // padding-right: 90px;
        .type-list {
          
          .active {
            background-color: #B0E0E6;;
          }
          li {
            float: left;
            display: block;
            margin-right: 30px;
            line-height: 40px;
            text-align: center;
            width: 50px;
            a {
              display: block;
              width: 100%;
              text-decoration: none;
              color: #666;
              text-align: center;
            }
          }
        }
      }

      .ext {
        position: absolute;
        top: 10px;
        right: 10px;

        .sui-btn {
          display: inline-block;
          padding: 2px 14px;
          box-sizing: border-box;
          margin-bottom: 0;
          font-size: 12px;
          line-height: 40px;
          text-align: center;
          vertical-align: middle;
          cursor: pointer;
          padding: 0 10px;
          background: #fff;
          border: 1px solid #d5d5d5;
        }

        a {
          color: #666;
        }
      }
    }
  }
</style>